<!--#Include File="../conn.asp" -->
<!--#Include File="comm/inc.asp" -->
<!--#Include File="../include/cls_template.asp"-->
<%
'====================================================================
'= Team Elite - Elite Article System
'= Copyright (c) 2005 - 2006 Eason Chan All Rights Reserved.
'=-------------------------------------------------------------------
'= 版权协议：
'=	GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991)
'=-------------------------------------------------------------------
'= 文件名称：/Manager/Admin_MakeView.asp
'= 摘    要：后台-HTML栏目页生成文件
'=-------------------------------------------------------------------
'= 最后更新：eason007
'= 最后日期：2006-02-18
'====================================================================

Server.ScriptTimeout=9999999

Call EA_Manager.Chk_IsMaster

If Not EA_Manager.Chk_Power(Admin_Power,"43") Then 
	ErrMsg=str_Comm_NotAccess
	Call EA_Manager.Error(1)
End If

Dim Atcion
Atcion=Request.QueryString ("atcion")

Select Case LCase(Atcion)
Case "mark"
	Set EA_Temp=New cls_Template
			
	Call MarkView
Case Else
	Call Main
End Select

Sub Main
	Dim Level,Temp,i
	Dim ColumnList

	Temp=EA_DBO.Get_Column_List()
	If IsArray(Temp) Then
		For i=0 To UBound(Temp,2)
			Level=(Len(Temp(2,i))/4-1)*2
			ColumnList = ColumnList & "<option value="""&Temp(0,i)&""">"
			If Len(Temp(2,i))>4 Then ColumnList = ColumnList & "├"
			ColumnList = ColumnList & String(Level,"-")
			ColumnList = ColumnList & Temp(1,i)&"</option>"
		Next
	End If

	PageContent=Template.LoadTemplate("admin_makeview_main.htm")

	Template.SetVariable "Language_Comm_Submit_Button",str_Comm_Submit_Button,PageContent

	Template.SetVariable "ColumnList",ColumnList,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_MakeView_Help",str_MakeView_Help,PageContent

	Template.SetVariable "Language_MakeView_Title",str_MakeView_Title,PageContent
	Template.SetVariable "Language_MakeView_MakeById",str_MakeView_MakeById,PageContent
	Template.SetVariable "Language_MakeView_StartId",str_MakeView_StartId,PageContent
	Template.SetVariable "Language_MakeView_EndId",str_MakeView_EndId,PageContent
	Template.SetVariable "Language_MakeView_MakeByDate",str_MakeView_MakeByDate,PageContent
	Template.SetVariable "Language_MakeView_StartDate",str_MakeView_StartDate,PageContent
	Template.SetVariable "Language_MakeView_EndDate",str_MakeView_EndDate,PageContent
	Template.SetVariable "Language_MakeView_MakeByColumn",str_MakeView_MakeByColumn,PageContent
	Template.SetVariable "Language_MakeView_AllColumn",str_Comm_AllColumn,PageContent


	Template.BaseReplace PageContent
	Template.OutStr PageContent
End Sub

Sub MarkView
	Call EA_Pub.Chk_Post
	
	Dim TopicList,i,j
	Dim Tag
	Dim StartBorder,EndBorder
	Dim WSQL
	
	Tag=EA_Pub.SafeRequest(2,"tag",0,0,0)
	
	Select Case Tag
	Case 1
		StartBorder=EA_Pub.SafeRequest(2,"sid",0,0,0)
		EndBorder=EA_Pub.SafeRequest(2,"eid",0,0,0)
		
		WSQL=" And a.[id] between "&StartBorder&" and "&EndBorder
	Case 2
		StartBorder=EA_Pub.SafeRequest(2,"date1",2,"1970-1-1",0)
		EndBorder=EA_Pub.SafeRequest(2,"date2",2,Date(),0)
		
		If iDataBaseType=0 Then
			WSQL=" And AddDate between #"&StartBorder&"# and #"&DateAdd("d",1,EndBorder)&"#"
		Else
			WSQL=" And AddDate between '"&StartBorder&"' and '"&EndBorder&"'"
		End If
	Case 3
		StartBorder=EA_Pub.SafeRequest(2,"column_id",0,0,0)
		
		If StartBorder<>0 Then WSQL=" And ColumnId="&StartBorder
	Case 4
		StartBorder=EA_Pub.SafeRequest(2,"sid",1,"",0)

		If Len(StartBorder)>0 Then WSQL=" And a.[id] In ("&StartBorder&")"
	End Select
		
		'0=ColumnId,1=ColumnCode,2=ColumnName,3=Title,4=Summary,5=Content,6=ViewNum,7=AuthorId,8=Author,9=CommentNum,10=IsOut
		'11=OutUrl,12=[KeyWord],13=AddDate,14=CutArticle,15=Source,16=SourceUrl,17=TColor,18=Img,19=IsTop,20=ListPower
		'21=IsHide,22=Article_TempId,23=[Id],24=TrueTime
		SQL="Select ColumnId,ColumnCode,ColumnName,a.Title,Summary,Content,a.ViewNum,AuthorId,Author,CommentNum,a.IsOut"
		SQL=SQL&",a.OutUrl,[KeyWord],AddDate,CutArticle,Source,SourceUrl,TColor,Img,a.IsTop,b.ListPower,b.IsHide,b.Article_TempId,a.[Id],TrueTime"
		SQL=SQL&" FROM NB_Content AS a INNER JOIN NB_Column AS b ON a.ColumnId=b.Id Where IsPass="&EA_M_DBO.TrueValue&" And IsDel=0 "&WSQL&" Order By ColumnId"
		'response.write sql
		Set Rs=Conn.Execute(SQL)
		If Not rs.eof And Not rs.bof Then 
			TopicList=Rs.GetRows()

			PageContent=Template.LoadTemplate("admin_makeview_view.htm")

			Template.SetVariable "PageTotal",Ubound(TopicList,2)+1,PageContent
			Template.SetVariable "Language_MakeList_Now",str_MakeList_Now,PageContent
			Template.SetVariable "Language_MakeList_Page",str_MakeList_Page,PageContent

			Template.BaseReplace PageContent
			Response.Write PageContent

			PageContent = ""

			Dim CurrentTemplateId
			Dim IsReplace
			Dim PageContent,ArticleContent,PageKeyword
			Dim TempStr,TempArray
			Dim Folder,sHTMLFilePath
			Dim FirstArticle,NextArticle
			Dim NewFolderList
			Dim re
			Dim Tmp

			Set re=New RegExp
			re.IgnoreCase =true
			re.Global=True
			re.Pattern=Replace(SystemFolder, "/", "\/") & "(.*)\/(\w+).(\w+)"

			NewFolderList = ","
			
			PageKeyword = EA_Pub.SysInfo(16)
			j=0
			
			For i=0 To Ubound(TopicList,2)
				IsReplace=True
				sHTMLFilePath=EA_Pub.Cov_ArticlePath(TopicList(23,i), TopicList(13,i), TopicList(24,i),"0")'html生成路径
				
				'check folder isexists
				Folder = re.Replace(sHTMLFilePath,"/$1/")

				If InStr(NewFolderList, "," & Folder & ",") = 0 Then
					If Not(EA_Pub.CheckDir(".." & Folder)) Then 
						TempArray = Split(Folder, "/")
						Tmp = ""

						For j = 1 To UBound(TempArray)-1
							Tmp = Tmp & "/" & TempArray(j)

							If InStr(NewFolderList, "," & Tmp & "/,") = 0 Then
								If Not(EA_Pub.CheckDir(".." & Tmp)) Then EA_Pub.MakeNewsDir Server.MapPath(".." & Tmp)
								NewFolderList = NewFolderList & Tmp & "/,"
							End If
						Next
					End If
				End If
				
				'check is member
				If TopicList(20,i)>0 Or TopicList(21,i)<>0 Then
					IsReplace=False
					TempStr="<meta http-equiv=""refresh"" content=""0;URL="&SystemFolder&"article.asp?articleid="&TopicList(23,i)&""">"
				End If
				
				'check is out
				If TopicList(10,i) And IsReplace Then
					IsReplace=False
					TempStr="<meta http-equiv=""refresh"" content=""0;URL="&TopicList(11,i)&""">"
				End If
				
				'load template
				If CurrentTemplateId<>TopicList(22,i) And IsReplace Then
					CurrentTemplateId=TopicList(22,i)
					PageContent=EA_Temp.Load_Template(CurrentTemplateId,"view")
				End If

				If Len(PageContent)<=0 And IsReplace Then
					Response.Write "栏目[ "&TopicList(2,i)&" ]尚未设定文章页模版，导致文章："&TopicList(3,i)&" 未能生成HTML。<br>"
				End If
				
				If Not IsReplace Then
				'not replace template tag
					Call EA_Pub.Save_HtmlFile(sHTMLFilePath,TempStr)
				Else
					TempStr=PageContent

					FirstArticle=EA_DBO.Get_Article_FirstArticle(TopicList(0,i),TopicList(24,i),TopicList(23,i))
					NextArticle=EA_DBO.Get_Article_NextArticle(TopicList(0,i),TopicList(24,i),TopicList(23,i))
					
					EA_Temp.Title=TopicList(3,i)&"/"&TopicList(2,i)&" - "&EA_Pub.SysInfo(0)
					EA_Temp.Nav="<a href="""&SystemFolder&""">"&EA_Pub.SysInfo(0)&"</a>"&EA_Pub.Get_NavByColumnCode(TopicList(1,i))&" >> 正文"

					TopicList(5,i)=EA_Pub.Cov_InsideLink(TopicList(5,i),TopicList(0,i))
					TempArray=Split(TopicList(14,i),"|")
					
					If TempArray(0)="1" Or TempArray(0)="2" Then 
						ArticleContent="<div id=""article""></div>"&vbcrlf
						
						ArticleContent=ArticleContent&"<xml id=""xmlArticle"">"&vbcrlf
						ArticleContent=ArticleContent&"<Article>"&vbcrlf
						ArticleContent=ArticleContent&"<Info>"&vbcrlf
						ArticleContent=ArticleContent&"<Content>"&vbcrlf
						
						ArticleContent=ArticleContent&"<![CDATA["&vbcrlf
						ArticleContent=ArticleContent&TopicList(5,i)
						ArticleContent=ArticleContent&"]]>"&vbcrlf
						
						ArticleContent=ArticleContent&"</Content>"&vbcrlf
						ArticleContent=ArticleContent&"</Info>"&vbcrlf
						ArticleContent=ArticleContent&"</Article>"&vbcrlf
						ArticleContent=ArticleContent&"</xml>"&vbcrlf
						
						ArticleContent=ArticleContent&"<script type=""text/javascript"">"&vbcrlf
						ArticleContent=ArticleContent&"//每页显示字数"&vbcrlf
						ArticleContent=ArticleContent&"PageSize="&TempArray(1)&";"&vbcrlf
						ArticleContent=ArticleContent&"//分页模式"&vbcrlf
						ArticleContent=ArticleContent&"flag="&TempArray(0)&";"&vbcrlf
						ArticleContent=ArticleContent&"</script>"&vbcrlf
						ArticleContent=ArticleContent&"<!--正文分页Js-->"&vbcrlf
						ArticleContent=ArticleContent&"<script type=""text/javascript"" src="""&SystemFolder&"js/cutarticle.js""></script>"&vbcrlf
						ArticleContent=ArticleContent&"<script type=""text/javascript"">"&vbcrlf
						ArticleContent=ArticleContent&"text_pagination(1);"&vbcrlf
						ArticleContent=ArticleContent&"</script>"&vbcrlf
					Else
						ArticleContent="<div id=""article"">"&TopicList(5,i)&"</div>"
					End If

					EA_Temp.ReplaceTag "ColumnId",TopicList(0,i),TempStr
					EA_Temp.ReplaceTag "ArticleId",TopicList(23,i),TempStr
					EA_Temp.ReplaceTag "ArticleTitle",EA_Pub.Add_ArticleColor(TopicList(17,i),TopicList(3,i)),TempStr
					EA_Temp.ReplaceTag "ArticlePostTime",TopicList(13,i),TempStr
					EA_Temp.ReplaceTag "ArticleText",ArticleContent,TempStr
					EA_Temp.ReplaceTag "ArticleAuthor","<a href='"&SystemFolder&"florilegium.asp?a_name="&TopicList(8,i)&"&amp;a_id="&TopicList(7,i)&"' rel=""external"">"&TopicList(8,i)&"</a>",TempStr
					
					If Len(TopicList(16,i))>0 Then
						EA_Temp.ReplaceTag "ArticleFrom","<a href='"&TopicList(16,i)&"' rel=""external"">"&TopicList(15,i)&"</a>",TempStr
					Else
						EA_Temp.ReplaceTag "ArticleFrom","本站",TempStr
					End If
					
					EA_Temp.ReplaceTag "ArticleViewTotal","<script type=""text/javascript"" src="""&SystemFolder&"articleinfo.asp?action=viewtotal&amp;articleid="&TopicList(23,i)&"""></script>",TempStr
					EA_Temp.ReplaceTag "ArticleCommentTotal","<script type=""text/javascript"" src="""&SystemFolder&"articleinfo.asp?action=commenttotal&amp;articleid="&TopicList(23,i)&"""></script>",TempStr

					If IsArray(FirstArticle) Then
						TempStr=Replace(TempStr,"{$FirstArticle$}","<a href='"&EA_Pub.Cov_ArticlePath(FirstArticle(0,0),FirstArticle(3,0),FirstArticle(4,0),EA_Pub.SysInfo(18))&"' rel=""external"">"&EA_Pub.Add_ArticleColor(FirstArticle(2,0),FirstArticle(1,0))&"</a>")
					Else
						TempStr=Replace(TempStr,"{$FirstArticle$}","<span style=""color: #800000;"">已到尽头</span>")
					End If
					If IsArray(NextArticle) Then
						TempStr=Replace(TempStr,"{$NextArticle$}","<a href='"&EA_Pub.Cov_ArticlePath(NextArticle(0,0),NextArticle(3,0),NextArticle(4,0),EA_Pub.SysInfo(18))&"' rel=""external"">"&EA_Pub.Add_ArticleColor(NextArticle(2,0),NextArticle(1,0))&"</a>")
					Else
						TempStr=Replace(TempStr,"{$NextArticle$}","<span style=""color: #800000;"">已到尽头</span>")
					End If
					
					EA_Pub.SysInfo(16)=PageKeyword & "," & TopicList(12,i)
					EA_Pub.SysInfo(17)=TopicList(4,i)

					Call CorrList(TopicList(12,i),TopicList(0,i),TopicList(23,i),TempStr)

					TempStr=EA_Temp.Replace_PublicTag(TempStr)
					
					Call EA_Pub.Save_HtmlFile(sHTMLFilePath,TempStr)
				End If
				
				j=j+1
				
				If Ubound(TopicList,2)=0 Then 
					Response.Write "<script>img1.width=400;" & VbCrLf
				Else
					Response.Write "<script>img1.width=" & Fix((j/Ubound(TopicList,2)) * 400) & ";" & VbCrLf
				End If
				Response.Write "column_complete.innerHTML=""<font color=green>"&i+1&"</font>"";</script>" & VbCrLf
				Response.Flush
			Next
			
			Response.Write "<script>img1.width=400;"& VbCrLf
			Response.Write "make_msg.innerHTML="""&str_MakeList_AllComplate&""";</script>" & VbCrLf
		End If
End Sub

Sub CorrList(Keyword,ColumnId,ArticleId,ByRef PageContent)
	Dim ConfigParameterArray

	ConfigParameterArray=EA_Temp.Find_TemplateTagValues("CorrList",PageContent)

	If IsArray(ConfigParameterArray) Then 
		If UBound(ConfigParameterArray) < 8 Then 
			ReDim Preserve ConfigParameterArray(8)
			ConfigParameterArray(8) = "5"
		End If

		If Keyword <> "" Then
			Dim TempArray,i,TempStr,SearchKeyWord

			TempArray=Split(Keyword,",")

			For i=0 To UBound(TempArray)
				Select Case iDataBaseType
				Case 0
					SearchKeyWord=SearchKeyWord&" InStr(','+keyword+',',',"&TempArray(i)&",')>0 or "
				Case 1
					SearchKeyWord=SearchKeyWord&" CharIndex(',"&TempArray(i)&",',','+keyword+',')>0 or "
				End Select
			Next
		
			TempArray=EA_DBO.Get_Article_CorrList(SearchKeyWord,ArticleId,ColumnId,CInt(ConfigParameterArray(8)))
		End If

		TempStr=EA_Temp.Text_List(TempArray,CInt(ConfigParameterArray(0)),CInt(ConfigParameterArray(1)),CInt(ConfigParameterArray(2)),CInt(ConfigParameterArray(3)),CInt(ConfigParameterArray(4)),CInt(ConfigParameterArray(5)),CInt(ConfigParameterArray(6)),CInt(ConfigParameterArray(7)),CInt(ConfigParameterArray(8)))

		Call EA_Temp.Find_TemplateTagByInput("CorrList",TempStr,PageContent)
	End If
End Sub
%>